package cn.tedu.jsd2206csmall.product.controller;

import cn.tedu.jsd2206csmall.product.pojo.dto.AlbumAddNewDTO;
import cn.tedu.jsd2206csmall.product.pojo.dto.CategoryAddNewDTO;
import cn.tedu.jsd2206csmall.product.service.IAlbumService;
import cn.tedu.jsd2206csmall.product.service.ICategoryService;
import cn.tedu.jsd2206csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/categories")
@Api(tags = "01. 类别管理模块")
public class CategoryController {

    @Autowired
    ICategoryService categoryService;

    public CategoryController() {
        System.out.println("创建控制器类对象：CategoryController");
    }

    // http://localhost:9080/categories/add-new
    @ApiOperation("添加类别")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@RequestBody CategoryAddNewDTO categoryAddNewDTO) {
        log.debug("开始处理【添加相册】的请求，参数：{}", categoryAddNewDTO);
        //System.out.println("开始处理【添加相册】的请求，参数：{}"+ albumAddNewDTO);
        categoryService.addNew(categoryAddNewDTO);
        return JsonResult.ok();
    }

    // http://localhost:9080/categories/9527/delete
    @ApiOperation("删除类别")
    @ApiOperationSupport(order = 200)
    public JsonResult delete(@PathVariable Long id) {
        log.debug("开始处理【删除相册】的请求，参数：{}", id);
        categoryService.deleteById(id);
        return JsonResult.ok();
    }

}
